
$(function() {

    $(document).on('infinite', '.infinite-scroll-bottom',function() {
        if(!isLoading) {
            console.log("infinite")
            firstLevelThings(2, 0);
            isLoading = true;
        }
        // 判断 再下拉没有数据了  执行此方法
        // $.detachInfiniteScroll($('.infinite-scroll'));
    })
})
function firstLevelThings(style , infinite) {

    $.getJSON("/product/loadList", {id: id,pageNum:page_size,infinite: infinite},
        function (data) {
            if(data.productList.length == 0) $.detachInfiniteScroll($('.infinite-scroll'));
            else  $.attachInfiniteScroll($('.infinite-scroll'));
            if(data.success){
                page_size += 1;
                var gettpl = document.getElementById('product_list_tpl').innerHTML;
                laytpl(gettpl).render(data.productList, function (html) {
                    if(style == 1) {
                        console.log("html===",data.productList);
                        document.getElementById('productList').innerHTML = html;
                        $("#productList").scrollTop(0);
                    }else
                         $('#productList').append(html);
                    setTimeout(function() {
                        $.hidePreloader();
                    }, 300);
                    $.refreshScroller();
                });
            }else {
                // $.hidePreloader();
                // $.alert(data.msg);
            }
            isLoading = false;
        })

}

function initShowPro(index){
    $(".menu li").removeClass("active");
    $('#firstType_'+index).parent().addClass("active");
    $.getJSON("/product/loadList", {id: 0,pageNum:page_size},
        function (data) {
            if(data.productList.length == 0) $.detachInfiniteScroll($('.infinite-scroll'));
            else  $.attachInfiniteScroll($('.infinite-scroll'));
            if(data.success){
                page_size += 1;
                var gettpl = document.getElementById('product_list_tpl').innerHTML;
                laytpl(gettpl).render(data.productList, function (html) {
                    document.getElementById('productList').innerHTML = html;
                    $("#productList").scrollTop(0);
                    $.refreshScroller();
                });
            }else {
                // $.hidePreloader();
                // $.alert(data.msg);
            }
            isLoading = false;
        })
    // $.showPreloader();

}
